package com.zxq.ai.domain.activity.strategy;

import com.zxq.ai.domain.user.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CollaborativeCompletionStrategy implements CompletionStrategy {

    private boolean isCompleted;
    private Map<String, Boolean> userCompletionStatus;

    public CollaborativeCompletionStrategy() {
        this.isCompleted = false;
        this.userCompletionStatus = new HashMap<>();
    }

    public void markCompleted(String userId) {
        this.isCompleted = true;
        userCompletionStatus.put(userId, true);
    }

    @Override
    public boolean isUserCompleted(String userId) {
        return userCompletionStatus.getOrDefault(userId, false);
    }

    @Override
    public boolean isCompleted(List<User> participants) {
        if(!isCompleted) {
            return false;
        }

        for(User user : participants) {
            if (!userCompletionStatus.getOrDefault(user.getUserId(), false)){
                return false;
            }
        }
        return true;
    }
}
